<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>分时问候</title>
  </head>
  <body>
    <div>早上好</div>
    <img src="moring.png" alt="moring" title="moring" />
    <script>
      var div = document.querySelector("div");
      var img = document.querySelector("img");
      var judgeTime = function () {
        let nowHour = new Date().getHours();
        if (nowHour >= 6 && nowHour < 12);
        else if (nowHour >= 12 && nowHour < 18) {
          div.innerHTML = "中午好";
          img.src = "afternoon.png";
          img.alt = "afternoon";
          img.title = "afternoon";
        } else {
          div.innerHTML = "晚上好";
          img.src = "evening.png";
          img.alt = "evening";
          img.title = "evening";
        }
      };
      judgeTime();
    </script>
  </body>
</html>
